package fms.admin;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;

import javax.sql.DataSource;

import org.apache.ibatis.datasource.pooled.PooledDataSource;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.mapping.Environment;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.Model;

import fms.classes.TestClass;
import fms.models.*;

public class AddTest extends WebPage {
	
	private Model testModel = new Model();

	
	public AddTest(){
		
		
		Form addTestForm = new Form("addTestForm");
		
		TextField name = new TextField("name", testModel);
		name.setEnabled(true);
		addTestForm.add(name);
		
		add(addTestForm);
	
		
		Button testButton = new Button("addTestButton"){
			public void onSubmit(){
			
				String name1 = (String)testModel.getObject();
				
				int name = Integer.parseInt(name1);
				
					TestClass testName = new TestClass(name);
					
				
					System.out.println("Hello opensession");
				/*
					try{
						SqlSession session = sqlSessionFactory.openSession();
						System.out.println("session address:" + session);
						session.insert("TestClass.insertTestUser", testName );
						System.out.println("commit");
						session.commit();
						
					}catch(Exception e){ 
						System.out.println("failed to opensession");
						e.printStackTrace();
						}
			 */
			
					TestDAO connect = new TestDAO();
					
					try{
					
					TestClass test1 = connect.selectTestClass(name);
					System.out.println("test 1 : " + test1);
					
					}catch(Exception e){
						System.out.println("\n\n this fails \n\n");
					}
					
					//TestClass test1 = connect.selectTestClass(name);
					//connect.insertTestClass(testName);
				
			}
		};
		
		addTestForm.add(testButton);
		
	}

}
